<?php
$dt = new DataTable(constant('DB_TABLE_PRODUCT'));
$GLOBALS['GV_IMAGE_PATH'] = 'product/';
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if ( $act == 'set_delete') {
	$update_data = array('id'=>intval($_REQUEST['id']), 'is_delete'=>'Y');
	$dt->save($update_data);
}
else if (  $act == 'delete' ) {
	$row = $dt->get($_REQUEST['id']);
	if ( $row ) {
		$GLOBALS['APP_INSTANCE']->removeFile($row['img_path'],$GLOBALS['GV_IMAGE_PATH']);
		$dt->remove($row['id']);
	}
}
$condition = "`is_delete`='N'";

if ( isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] > 0) {
	$condition .= sprintf(" AND `cat_id`=%d", $_REQUEST['cat_id']);
}
if (  isset($_REQUEST['key_word']) && strlen($_REQUEST['key_word']) > 0 ) {
	$condition .= sprintf(" AND `name` like '%%%s%%'", Util::sql_safe($_REQUEST['key_word']));
}
$page = isset($_REQUEST['page'])?$_REQUEST['page']:1;
$page_size = isset($_REQUEST['page_size'])?$_REQUEST['page_size']:10;
$offset = $page_size * ( $page - 1);
$GLOBALS['PAGE_LIST_DATA'] = $dt->get_list($condition, array('-date','-id'), $page_size, $offset);
$total_row =  $dt->get_count($condition);
$GLOBALS['PAGE_LIST_TOTAL_PAGE'] = ceil($total_row/$page_size);
$GLOBALS['PAGE_LIST_PAGE'] = $page;
$_REQUEST['page'] = $page;
?>